package com.cs.base.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import java.util.List;

/**
 * @ClassName: BaseFragmentStateAdapter
 * @Date: 2021/6/17
 * @Author: CS
 * @Description: 适配androidx.viewpager2.widget.ViewPager2
 */
public class BaseFragmentStateAdapter<F extends Fragment> extends FragmentStateAdapter {

    private final List<F> fragments;

    public BaseFragmentStateAdapter(@NonNull FragmentActivity fragmentActivity, List<F> fragments) {
        super(fragmentActivity);
        this.fragments = fragments;
    }


    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragments.get(position);
    }

    @Override
    public int getItemCount() {
        return fragments.size();
    }
}
